package com.atguigu.controller;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.atguigu.util.DLX;
import com.atguigu.util.Reversion;
import com.fasterxml.jackson.annotation.JsonAlias;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
public class HelloController {

    @RequestMapping("hello")
    public String hello() {
        return "Hello World";
    }

    @RequestMapping("getsodoku")
    public String getsodoku() {
        return Reversion.run();
    }

    @PostMapping("getanswer")
    public String getanswer(@RequestBody Map<String,String> params) {
        String sodoku = params.get("sodoku");
        if(sodoku==null) return JSON.toJSON(new int[9][9]).toString();
        int[][] data = JSON.parseObject(sodoku,int[][].class);
        if(DLX.hasSolve(data)){
            return JSON.toJSON(DLX.run(data)).toString();
        }
        return JSON.toJSON(new int[9][9]).toString();
    }
}
